<include file="Public:head" />
<link href="__PUBLIC__/css/say.css" type="text/css" rel="Stylesheet" />
<script type="text/javascript" src="__PUBLIC__/js/jquery/textarea.js"></script>
<script type="text/javascript" src="__PUBLIC__/js/jquery/jquery.qqFace.js"></script>

<script type="text/javascript">
    function checkUserLogin(){
        var loginUrl = "{:U('Login/index')}";
            showTip('系统提示',"亲，请先<a style='color:#016FBC' href='"+loginUrl+"'>登录</a>！",'2');
    }
    function saysub(){
        if( "{$Think.session.userid}" == ''){
            checkUserLogin();
            return false;
        }
      
        var con = $('#saybox_0').val();
        var len = con.length;
        if(len  == 0){
            showTip('系统提示',"发布内容不能为空！",'2',1.5);
            return false;
        }
        if(len  > 140){
            showTip('系统提示',"发布内容不能超过140字！",'2',1.5);
            return false;
        }
        $.post("{:U('Ajax/say')}",{
            con:con
        },function(data){
            showTip('系统提示',"发布成功！",'2','1.5','',"{:U('Say/index')}");
        })
    }
    function replace_em(str){
        var url = $('#siteurl').val();
        str = str.replace(/\</g,'&lt;');
        str = str.replace(/\>/g,'&gt;');
        str = str.replace(/\n/g,'<br/>');
        str = str.replace(/\[em_([0-9]*)\]/g,'<img src="__PUBLIC__/face/$1.gif" border="0" />');
        return str;
    }
    function checknum(v,word){
        var len = 140-v.length;
        $('#sayword_'+word).text(len);
        if(len <0){
            $('#sayword_'+word).css({
                "color":"red"
            });
        }
    }
    function lysub(id){
        if( "{$Think.session.userid}" == ''){
            checkUserLogin();
            return false;
        }
        var con = $('#ly_'+id).children('textarea').val();
        var len = con.length;
        if(len  == 0){
            showTip('系统提示',"留言内容不能为空！",'2');
            return false;
        }
        if(len  > 140){
            showTip('系统提示',"留言内容不能超过140字！",'2');
            return false;
        }
        $.post("__APP__/index.php/Ajax/say",{
            id:id,
            con:con
        },function(data){
            var name = '{$user.name}';
            var dl = "<dl><dd><div class='userPic30'>\n\
<img src='__APP__/{$user.avatar}'>\n\
</div><div class='userTalkFont2'><p>\n\
<span class='org'>{$user.name}</span>："+replace_em(con)+"</p><h4>刚刚\n\
</h4></div></dd></dl>";
            $('#ly_'+id).after(dl);
            $('.ly').empty();
            
        })
    }
    
  
    function emotion(div,id){
        $('#'+div).qqFace({
            id : 'facebox', //表情盒子的ID
            assign:'saybox_'+id+'', //给那个控件赋值
            path:'__PUBLIC__/face/'	//表情存放的路径
        });
    }
    function ly(id){
        if( "{$Think.session.userid}" == ''){
            checkUserLogin();
            return false;
        }
        var box = "<textarea id='saybox_"+id+"'class='textarea_say' onkeyup=checknum(this.value,"+id+")></textarea>\n\
<div class='tbtnarea'><span class='emotion'id='face_"+id+"'onclick='emotion(this.id,"+id+")'>表情</span><div class='tbtn fr'>\n\
<a id='comment' class='btn68 fl' onclick='lysub("+id+")'>评 论</a>\n\
<span class='wordnum'>还可以输入<span id='sayword_"+id+"'>140</span>字</span>\n\
</div><div class='cl'></div></div>";
        $('.ly').empty();
        $('#ly_'+id).html(box);
        $('#ly_'+id).children('textarea').focus();
    }
    function reply(id,rid){
        if( "{$Think.session.userid}" == ''){
            checkUserLogin();
            return false;
        }
        var name = $('#dd_'+rid).find('span.org').text();
        var box = "<dd class='ddreply'>\n\
<textarea class='textarea_say'id='saybox_"+id+"'onkeyup=checknum(this.value,'sayword')>\n\
回复&nbsp;"+name+"&nbsp;</textarea>\n\
<div class='tbtnarea'><span class='emotion'id='face_"+id+"'onclick='emotion(this.id,"+id+")'>表情</span><div class='tbtn fr'>\n\
<a id='comment' class='btn68 fl' onclick='replysub("+id+","+rid+")'>回 复</a>\n\
<span class='wordnum'>还可以输入<span id='sayword'>140</span>字</span>\n\
</div><div class='cl'></div></div></dd>";
        $('.ly').empty();
        $('.ddreply').remove();
        if($('#dl_'+id).find('textarea').length == 0){
            $('#dl_'+id).append(box);
        }
        $('#saybox_'+id).focus();
        $('#saybox_'+id).CurPosition('saybox_'+id);
    }
    function replysub(id){
        if( "{$Think.session.userid}" == ''){
            checkUserLogin();
            return false;
        }
        var con = $('#dl_'+id).find('textarea').val();
        var len = con.length;
        if(len  == 0){
            showTip('系统提示',"留言内容不能为空！",'2');
            $('#dl_'+id).find('textarea').focus();
            return false;
        }
        if(len  > 140){
            showTip('系统提示',"回复内容不能超过140字！",'2');
            $('#dl_'+id).find('textarea').focus();
            return false;
        }
        $.post("__APP__/index.php/Ajax/say",{
            id:id,
            con:con
        },function(data){
            var dl = "<dd style='padding-left:45px'><div class='userPic30'>\n\
<img src='{$user.avatar|getUserAvatar=###,130}'>\n\
</div><div class='userTalkFont2'><p>\n\
<span class='org'>{$user.name}</span>："+replace_em(con)+"</p><h4>刚刚\n\
</h4></div></dd>";
            $('#dl_'+id).append(dl);
            $('#dl_'+id).find('textarea').parent('dd').remove();
        })
    }
   
</script>

<div class="container">
    <div class="talk">
        <h1>我要说说：</h1>

        <div class="talkBox">
            <p>
                <textarea id="saybox_0" autocomplete="off" class="talkText textarea_say" onkeyup="checknum(this.value,'0')" name="say"></textarea>
            </p>
            <div class="saybtnarea">
                <span class="emotion" id="face_0" onclick="emotion(this.id,0)">表情</span>
                <div class="saybtn">
                    <input class="btn128 fl" type="button" onclick="saysub()" value="确定发布">
                    <span  class="fl mlr5">还可以输入<span id="sayword_0">140</span>字</span>
                </div>
            </div>
        </div>

        <h1>所有说说：</h1>
        <div class="talkList">
            <ul id="userTalkListUl">
                <foreach name="say" item="row">
                    <li>
                        <span class="talkListIcon"></span>
                        <div class="talkListText" style="width:820px;">
                            <div class="userPic50">
                                <img  id="img_{$row.id}" src="{$row.avatar|getUserAvatar=###,130}">
                            </div>
                            <div class="userTalkFont">
                                <h3><span id="name_{$row.id}">{$row.uid|getSingleField=###,'user','name'}</span>：</h3>
                                <p>{$row.content|ubbReplace=###}</p>
                                <h4>
                                    <span>
                                        <a class="org" onclick="ly('{$row.id}')">评论</a>
                                    </span>
                                    {$row.addtime|tranTime=###}
                                </h4>
                                <div id="ly_{$row.id}" class="ly">
                                </div>
                                <foreach name="row['huifu']" item="row2">
                                    <dl id="dl_{$row2.id}">
                                        <dd id="dd_{$row2.id}">
                                            <div class="userPic30">
                                                <img src="{$row2.avatar|getUserAvatar=###,130}">
                                            </div>
                                            <div class="userTalkFont2">
                                                <p>
                                                    <span class="org">{$row2.uid|getSingleField=###,'user','name'}</span>
                                                    {$row2.content|ubbReplace=###}
                                                </p>
                                                <h4>
                                                    {$row2.addtime|tranTime=###}
                                                    <a class="org" onclick="reply('{$row2.id}','{$row2.id}')">回复</a>
                                                </h4>
                                            </div>
                                        </dd>
                                        {$row2.id|getreplylist=###}
                                    </dl>
                                </foreach>
                            </div>
                        </div>
                    </li>
                </foreach>
            </ul>
            <div class="page">{$page}</div>
        </div>

    </div>
    <div class="cl"></div>
</div>
<include file="Public:foot" />
